package com.dbz.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dbz.dao.SupplierDao;
import com.dbz.entity.Supplier;
import com.dbz.entity.Warehousing;
import com.dbz.service.SupplierService;
import com.dbz.service.WarehousingService;
import jdk.nashorn.internal.runtime.JSONFunctions;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/warehousing/")
public class WarehousingController {
    @Resource
    private WarehousingService warehousingService;
    @Resource
    private SupplierService supplierService;
    @RequestMapping("selectPages")
     public Map selectPages(Integer page,Integer rows){
     Map<String,Object> map=new HashMap<String, Object>();
         QueryWrapper<Warehousing> queryWrapper=new QueryWrapper<>();
         IPage<Warehousing> page1=new Page<>(page,rows);
         map.put("rows",warehousingService.selectPage(page1,queryWrapper).getRecords());
         map.put("total",warehousingService.selectPage(page1,queryWrapper).getTotal());
         return map;
     }

    @RequestMapping("selectPagesaaa")
    public Map selectPagesaaa(Integer page,Integer rows){
        Map<String,Object> map=new HashMap<String, Object>();
        QueryWrapper<Warehousing> queryWrapper=new QueryWrapper<>();
        IPage<Warehousing> page1=new Page<>(page,rows);
        map.put("rows",warehousingService.selectPageaaa(page1,queryWrapper).getRecords());
        map.put("total",warehousingService.selectPageaaa(page1,queryWrapper).getTotal());
        return map;
    }

    /**
     * 批量添加 提交订单
     * @param data
     * @return
     */
    @RequestMapping(value = "insertwarehousing")
     public int add(@RequestParam String data){
        System.out.println(data+"111111111");
        String strlist=data;
        List<Object>array= JSON.parseArray(strlist);
        System.out.println(array+"222222222");
        warehousingService.insertWarehousing(array);
        return 1;
     }

    /**
     * 查询所有的供应商
     * @return
     */
    @RequestMapping("selectSupplierAll")
     public List<Supplier> selectSupplierAll(){
        return  supplierService.selectSupplierAll();
     }


    /**
     * 修改标识
     */
@RequestMapping("updatebiaoshi")
    public int updatebiaoshi(String wid){
        warehousingService.updatewareisbiaoshi(wid);
        return 1;
    }

}
